package com.aaa.demo11103;

import static com.aaa.demo11103.Test.lock;
import static com.aaa.demo11103.Test.lock1;

/**
 * @author 荆豪峰
 * @version 1.0
 */
public class Test {
    static Object lock=new Object();
    static Object lock1=new Object();
    public static void main(String[] args) {
        Pen pen = new Pen();
        Board board = new Board();
        board.start();
        pen.start();
    }
}
class Pen extends Thread{
    @Override
    public void run() {
       synchronized (lock){
           System.out.println(Thread.currentThread().getName()+"获取画笔");
           synchronized (lock1){
               System.out.println(Thread.currentThread().getName() + "获取画板");
               System.out.println(Thread.currentThread().getName() + "开始画画");
           }
       }
    }
}
class  Board extends Thread{
    @Override
    public void run() {
        synchronized (lock1){
            System.out.println(Thread.currentThread().getName()+"获取画板");
            synchronized (lock){
                System.out.println(Thread.currentThread().getName() + "获取画笔");
                System.out.println(Thread.currentThread().getName() + "开始画画");
            }
        }
    }
}